package com.zzjson.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.datasource.DataSourceFactory;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.datasource</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年07月15日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class DruidDataSourceFactory implements DataSourceFactory {
	private Properties props;

	@Override
	public void setProperties(Properties props) {
		this.props = props;
	}

	@Override
	public DataSource getDataSource() {
		DruidDataSource dds = new DruidDataSource();
		dds.setUrl(this.props.getProperty("url"));
		dds.setPassword(this.props.getProperty("password"));
		dds.setUsername(this.props.getProperty("username"));
		dds.setDriverClassName(this.props.getProperty("driver"));
		try {
			dds.init();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return dds;
	}
}